<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改家禽管理')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-WxPoultry-edit" th:object="${wxPoultry}">
        <input name="poultryId" th:field="*{poultryId}" type="hidden">
        <h4 class="form-header h4">基本信息</h4>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">选择农场：</label>
            <div class="col-sm-10">
                <input  id="Fid" th:value="*{poultryFid}"  hidden/>
                <select name="poultryFid" id="poultryFid"  class="form-control" type="text" required></select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">品种：</label>
            <div class="col-sm-10">
                <input name="poultryName" id="poultryName" th:field="*{poultryName}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">年龄：</label>
            <div class="col-sm-4">
                <input name="poultryAge" id="poultryAge" th:field="*{poultryAge}" class="form-control" type="text" required>
            </div>
            <label class="col-sm-2 control-label is-required">重量：</label>
            <div class="col-sm-4">
                <input name="poultryKg" id="poultryKg" th:field="*{poultryKg}" class="form-control" type="number" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">封面图：</label>
            <div class="col-sm-10">
                <input id="poultryPic" th:value="*{poultryPic}" type="hidden">
                <div class="upload" action='upload.html' data-num="1" data-value='' id='piclist_poultryPic'></div>
            </div>
        </div>
        <h4 class="form-header h4">费用配置</h4>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">领养定金：</label>
            <div class="col-sm-4">
                <input name="poultryPricing" id="poultryPricing" onkeyup="onlyNumber(this)" th:field="*{poultryPricing}" class="form-control" required
                       type="text">
            </div>
            <label class="col-sm-2 control-label is-required">每日费用：</label>
            <div class="col-sm-4">
                <input name="poultryDayFee" id="poultryDayFee" onkeyup="onlyNumber(this)" th:field="*{poultryDayFee}" class="form-control" required
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">出栏斤数：</label>
            <div class="col-sm-4">
                <input name="poultrySlaughterKg" id="poultrySlaughterKg" th:field="*{poultrySlaughterKg}" required
                       class="form-control" type="number">
            </div>
            <label class="col-sm-2 control-label is-required">管理费：</label>
            <div class="col-sm-4">
                <input name="poultryAdminFee" id="poultryAdminFee" onkeyup="onlyNumber(this)" th:field="*{poultryAdminFee}" class="form-control" required
                       type="text">
            </div>
        </div>
        <h4 class="form-header h4">功能配置</h4>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">出栏状态：</label>
            <div class="col-sm-10">
                <div class="radio-box" th:each="dict : ${@dict.getType('poultry_slaughter_state')}">
                    <input type="radio" th:id="${'poultrySlaughterState_' + dict.dictCode}" name="poultrySlaughterState"
                           th:value="${dict.dictValue}" th:field="*{poultrySlaughterState}">
                    <label th:for="${'poultrySlaughterState_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
    var prefix = ctx + "wechat/WxPoultry";


    $("#form-WxPoultry-edit").validate({
        focusCleanup: true
    });
    $.operate.ajaxGet(ctx + "/wechat/WxFarm/listAjax", function (result) {
        if(result.data.length==0){
            $.modal.alertError("暂无用户")
        }
        var html = "";
        for (var i = 0; i < result.data.length; i++) {
            html += "<option value='" + result.data[i].farmId + "'>" + result.data[i].farmName + "</option>";
        }
        $("#poultryFid").append(html);
        $("#poultryFid").val($("#Fid").val())
    })

    //轮播图上传
    $("#piclist_poultryPic").attr("data-value", $("#poultryPic").val())
    $("#piclist_poultryPic").upload(function () {
    }, "poultryPic")

    function onlyNumber(obj) {
        //得到第一个字符是否为负号    
        var t = obj.value.charAt(0);
        //先把非数字的都替换掉，除了数字和.和-号    
        obj.value = obj.value.replace(/[^\d\.\-]/g, '');
        // obj.value = obj.value.replace(/[^\d\-]/g,'');
        //前两位不能是0加数字      
        obj.value = obj.value.replace(/^0\d[0-9]*/g, '');
        //必须保证第一个为数字而不是.       
        obj.value = obj.value.replace(/^\./g, '');
        //保证只有出现一个.而没有多个.       
        obj.value = obj.value.replace(/\.{2,}/g, '.');
        obj.value = obj.value.replace(/\-{1,}/g, '.');
        //保证.只出现一次，而不能出现两次以上       
        obj.value = obj.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
        //如果第一位是负号，则允许添加    
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
        if (t == '-') {
            return;
        }
    }

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-WxPoultry-edit').serialize());
        }
    }
</script>
</body>
</html>
